<div class="layui-card">
    <div class="layui-card-header">
        <div class="layui-btn-group">
            <a class="layui-btn layui-btn-sm newTab" lay-href="<?php echo \yii\helpers\Url::to(['create']) ?>" ><i class="layui-icon layui-icon-add-1"></i>添加队列</a>
        </div>
    </div>
    <div class="layui-card-body">
        <table id="dataTable" lay-filter="dataTable"></table>
        <script type="text/html" id="options">
            <a lay-event="edit" class="layui-btn layui-btn-xs" ><i class="layui-icon layui-icon-edit"></i>编辑</a>
            <a lay-event="destroy" class="layui-btn layui-btn-xs layui-btn-danger" ><i class="layui-icon layui-icon-delete"></i>删除</a>
        </script>
    </div>
</div>


<?php
$url = yii\helpers\Url::to(['index']);
$js = <<<JS
    layui.use(['form','element','table', 'layer'],function() {
        var form = layui.form;  
        var element = layui.element;  
        var table = layui.table;  
        var layer = layui.layer;  
        
        var dataTable = table.render({
            elem: '#dataTable'
            ,height: 'full-200'
            ,url: '{$url}' 
            ,page: true 
            ,cols: [[ 
                {field: 'extension', title: '队列号码'}
                ,{field: 'descr', title: '名称'}
                ,{field: 'strategy', title: '响铃模式'}
                ,{field: 'cwignore_text', title: '跳过繁忙'}
                ,{field: 'monitor_type_text', title: '录音模式'}
                ,{field: 'monitor-format', title: '录音格式'}
                ,{title: '操作',toolbar:'#options'}
            ]]
        });
        
        //监听工具条
        table.on('tool(dataTable)', function(obj){ 
            var data = obj.data; 
            var layEvent = obj.event;
            if(layEvent === 'destroy'){ 
                console.log(data)
                layer.confirm('确认删除吗？', function(index){
                    $.post(data.destroy_url,{extension:data.extension},function(res) {
                        layer.msg(res.msg,{},function() {
                            if (res.code==0){
                                obj.del(); 
                                layer.close(index);
                            }   
                        })  
                    })
                });
            } else if(layEvent === 'edit'){ 
                location.href = data.edit_url
            }
        });
        
        
    });
JS;
$this->registerJs($js);
